import { defHttp } from '/@/utils/http/axios';
import { Modal } from 'ant-design-vue';

enum Api {
  list = '/contractType/list',
  getApiKey = '/aiApiConfig/apiKey/edit',
  save = '/contractType/add',
  edit = '/contractType/edit',
  deleteRole = '/contractType/delete/',
  deleteBatch = '/sys/role/deleteBatch',
  queryIndexByCode = '/sys/sysRoleIndex/queryByCode',
}

/**
 * 系统角色列表
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });
/**
 * 租户角色列表
 * @param params
 */
export const listByTenant = (params) => defHttp.get({ url: Api.listByTenant, params });

/**
 * 删除模型配置
 */
export const deleteRole = (params, handleSuccess) => {
  console.log(defHttp.delete)
  return defHttp.delete({ url: Api.deleteRole, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
/**
 * 批量删除角色
 * @param params
 */
export const batchDeleteRole = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};
/**
 * 保存或者更新角色
 * @param params
 */
export const saveOrUpdateRole = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  if(url == '/contractType/add'){
    return defHttp.post({ url: url, params });
  }else{
    return defHttp.post({ url: url, params });
  }
};



/**
 * 根据code查询首页配置
 * @param params
 */
export const queryIndexByCode = (params) => defHttp.get({ url: Api.queryIndexByCode, params }, { isTransformResponse: false });

